<template>
  <div class="detail">
    <el-card>
      <el-button type="primary" @click="dayinclick">打印</el-button>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="登录帐户设置" name="first">
          <el-form class="myform" label-width="100px">
            <el-form-item label="姓名">
              <el-input v-model="form.username"></el-input>
            </el-form-item>
            <el-form-item label="密码">
              <el-input v-model="form.password" type="password"></el-input>
            </el-form-item>
            <el-form-item class="mag">
              <el-button type="primary" @click="setuserinfo">更新</el-button>
              <el-button @click="$router.push('/employees')">取消</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人详情" name="second"
          ><userxq :userinfo="userinfo"></userxq
        ></el-tab-pane>
        <el-tab-pane label="岗位信息" name="third"
          ><jobinfo></jobinfo
        ></el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { userbatchinfo, setbatchinfo } from "@/api/employees";
import userxq from "./userxq.vue";
import jobinfo from "./jobinfo.vue";
export default {
  components: {
    userxq,
    jobinfo,
  },
  data() {
    return {
      activeName: "first",
      form: {
        username: "",
        password: "",
      },
      userid: 0,
      userinfo: {},
      id: 0,
    };
  },
  methods: {
    handleClick() {},
    dayinclick() {
      this.$router.push({
        path: "/print",
        query: { id: this.id, type: this.activeName },
      });
    },
    async setuserinfo() {
      setbatchinfo({ ...this.userinfo, ...this.form });
      this.$message.success("修改成功！");
    },
  },
  async created() {
    let res = await userbatchinfo(this.$route.query.id);
    this.id = this.$route.query.id;
    this.userinfo = res;
    this.form = {
      username: res.username,
      password: res.password,
    };
  },
};
</script>

<style lang="scss" scoped>
.detail {
  padding: 20px;
  .myform {
    width: 400px;
    margin-left: 200px;
  }
  .mag {
    padding-right: 30px;
  }
}
</style>
